package com.hutu.erp.catalog.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hutu.erp.catalog.domain.ProductPicture;
import com.hutu.erp.catalog.service.IProductPictureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品图片Controller
 * 
 * @author ruoyi
 * @date 2021-05-24
 */
@RestController
@RequestMapping("/catalog/product_picture")
public class ProductPictureController extends BaseController
{
    @Autowired
    private IProductPictureService productPictureService;

    /**
     * 查询商品图片列表
     */
    @PreAuthorize("@ss.hasPermi('catalog:product_picture:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductPicture productPicture)
    {
        startPage();
        List<ProductPicture> list = productPictureService.selectProductPictureList(productPicture);
        return getDataTable(list);
    }

    /**
     * 导出商品图片列表
     */
    @PreAuthorize("@ss.hasPermi('catalog:product_picture:export')")
    @Log(title = "商品图片", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProductPicture productPicture)
    {
        List<ProductPicture> list = productPictureService.selectProductPictureList(productPicture);
        ExcelUtil<ProductPicture> util = new ExcelUtil<ProductPicture>(ProductPicture.class);
        return util.exportExcel(list, "商品图片数据");
    }

    /**
     * 获取商品图片详细信息
     */
    @PreAuthorize("@ss.hasPermi('catalog:product_picture:query')")
    @GetMapping(value = "/{productPictureId}")
    public AjaxResult getInfo(@PathVariable("productPictureId") Long productPictureId)
    {
        return AjaxResult.success(productPictureService.selectProductPictureById(productPictureId));
    }

    /**
     * 新增商品图片
     */
    @PreAuthorize("@ss.hasPermi('catalog:product_picture:add')")
    @Log(title = "商品图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductPicture productPicture)
    {
        return toAjax(productPictureService.insertProductPicture(productPicture));
    }

    /**
     * 修改商品图片
     */
    @PreAuthorize("@ss.hasPermi('catalog:product_picture:edit')")
    @Log(title = "商品图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductPicture productPicture)
    {
        return toAjax(productPictureService.updateProductPicture(productPicture));
    }

    /**
     * 删除商品图片
     */
    @PreAuthorize("@ss.hasPermi('catalog:product_picture:remove')")
    @Log(title = "商品图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productPictureIds}")
    public AjaxResult remove(@PathVariable Long[] productPictureIds)
    {
        return toAjax(productPictureService.deleteProductPictureByIds(productPictureIds));
    }
}
